home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / fips11.zip / SOURCE / HDSTRUCT.H < prev    next >
C/C++ Source or Header  |  1994-05-25  |  6KB  |  167 lines

  1. /*
  2.     FIPS - the First nondestructive Interactive Partition Splitting program
  3.  
  4.     Module hdstruct.h
  5.  
  6.     RCS - Header:
  7.     $Header: c:/daten/fips/source/main/RCS/hdstruct.h 1.1 1994/05/25 22:20:25 schaefer Exp schaefer $
  8.  
  9.     Copyright (C) 1993 Arno Schaefer
  10.  
  11.     This program is free software; you can redistribute it and/or modify
  12.     it under the terms of the GNU General Public License as published by
  13.     the Free Software Foundation; either version 2 of the License, or
  14.     (at your option) any later version.
  15.  
  16.     This program is distributed in the hope that it will be useful,
  17.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.     GNU General Public License for more details.
  20.  
  21.     You should have received a copy of the GNU General Public License
  22.     along with this program; if not, write to the Free Software
  23.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  
  25.  
  26.     Report problems and direct all questions to:
  27.  
  28.     schaefer@rbg.informatik.th-darmstadt.de
  29. */
  30.  
  31. #ifndef HDSTRUCT_H
  32. #define HDSTRUCT_H
  33.  
  34. #include "types.h"
  35. #include "disk_io.h"
  36. #include "logdr_st.h"
  37.  
  38. /* ----------------------------------------------------------------------- */
  39. /* Class rootsector - derived from structure sector                        */
  40. /* Must be initialized with a pointer to a physical_drive object           */
  41. /* Read() and Write() read/write sector 0 of physical drive                */
  42. /* ----------------------------------------------------------------------- */
  43.  
  44. class rootsector:public sector
  45. {
  46.     physical_drive *drive;
  47. public:
  48.     int read (void) { return sector::read (drive,0); }
  49.     int write (void) { return sector::write (drive,0); }
  50.  
  51.     rootsector (physical_drive *drive) { rootsector::drive = drive; }
  52.     rootsector (rootsector &rs);
  53.     void operator= (rootsector &rs);
  54. };
  55.  
  56. /* ----------------------------------------------------------------------- */
  57. /* Partition Info Structure                                                */
  58. /* Each entry in the partition table contains this information             */
  59. /* ----------------------------------------------------------------------- */
  60.  
  61. struct partition_info
  62. {
  63.     byte bootable;                  // 80h or 0
  64.     byte start_head;                // location of first sector (bootsector)
  65.     word start_cylinder;
  66.     byte start_sector;
  67.     byte system;            // 1 = 12-bit FAT
  68.                     // 4 = 16-bit FAT & 16-bit sector number
  69.                     // 6 = 16-bit FAT & 32-bit sector number (BIGDOS)
  70.     byte end_head;                  // location of last sector
  71.     word end_cylinder;
  72.     byte end_sector;
  73.     dword start_sector_abs;         // = start_cylinder * heads * sectors
  74.                     // + start_head * sectors + start_sector - 1
  75.     dword no_of_sectors_abs;        // = end_cylinder * heads * sectors + end_head * sectors
  76.                     // + end_sector - start_sector_abs
  77. };
  78.  
  79. /* ----------------------------------------------------------------------- */
  80. /* Partition Table Structure                                               */
  81. /* The partition table consists of 4 entries for the 4 possible partitions */
  82. /* Get() reads the partition table from the rootsector, put() writes the   */
  83. /* data back into the rootsector buffer                                    */
  84. /* ----------------------------------------------------------------------- */
  85.  
  86. struct partition_table
  87. {
  88.     partition_info partition_info[4];
  89.     void get (rootsector *rootsector);
  90.     void put (rootsector *rootsector);
  91. };
  92.  
  93. /* ----------------------------------------------------------------------- */
  94. /* Harddrive Class, derived from physical_drive                            */
  95. /* Represents one physical harddrive. Must be initialized with the drive   */
  96. /* number (0x80 for 1st HDD). Contains the rootsector and partition table. */
  97. /* ----------------------------------------------------------------------- */
  98.  
  99. class harddrive:public physical_drive
  100. {
  101.     partition_table pr_partition_table;
  102. public:
  103.     rootsector *rootsector;
  104.     virtual partition_table &partition_table() { return pr_partition_table; }
  105.  
  106.     harddrive (int number):physical_drive (number)
  107.     {
  108.         rootsector = new class rootsector (this);
  109.     }
  110.     harddrive (harddrive &hd):physical_drive (hd)
  111.     {
  112.         rootsector = new class rootsector (*(hd.rootsector));
  113.         partition_table () = hd.partition_table();
  114.     }
  115.     void operator= (harddrive &hd);
  116.     ~harddrive (void) { delete rootsector; }
  117. };
  118.  
  119. /* ----------------------------------------------------------------------- */
  120. /* Raw Partition Class                                                     */
  121. /* Represents one partition from the partition table (may be non-DOS)      */
  122. /* Initialization with the pointer to the harddrive object and the         */
  123. /* partition number (0-3)                                                  */
  124. /* ----------------------------------------------------------------------- */
  125.  
  126. class raw_partition
  127. {
  128. public:
  129.     int number;
  130.     physical_drive *drive;
  131.     partition_info *partition_info;
  132.  
  133.     raw_partition (class harddrive *drive,int number)
  134.     {
  135.         raw_partition::number = number;
  136.         raw_partition::drive = drive;
  137.         partition_info = &(drive->partition_table().partition_info[number]);
  138.     }
  139. };
  140.     
  141. /* ----------------------------------------------------------------------- */
  142. /* Partition Class, derived from logical_drive and raw_partition           */
  143. /* Represents one primary DOS partition. Read_sector() and write_sector()  */
  144. /* are instances of the virtual functions in the logical_drive class       */
  145. /* ----------------------------------------------------------------------- */
  146.  
  147. class partition:public logical_drive,public raw_partition
  148. {
  149. public:
  150.     int read_sector (dword number,sector *sector)
  151.     {
  152.         return (sector->read (drive,partition_info->start_sector_abs + number));
  153.     }
  154.     int write_sector (dword number,sector *sector)
  155.     {
  156.         return (sector->write (drive,partition_info->start_sector_abs + number));
  157.     }
  158.  
  159.     partition (class harddrive *drive,int number):raw_partition(drive,number)
  160.     {
  161.         bootsector = new class bootsector (this);
  162.     }
  163.     ~partition (void) { delete bootsector; }
  164. };
  165.  
  166. #endif
  167.